package easy;

import java.util.Arrays;

/**
 * 26. 删除有序数组中的重复项
 * 创建时间：2024-04-08 13:53
 * 地址：https://leetcode.cn/problems/remove-duplicates-from-sorted-array/description/
 */
public class 删除有序数组中的重复项_26 {
    static class Solution {
        public int removeDuplicates(int[] nums) {
            int rsl = 1;
            for (int i = 1; i < nums.length; i++) {
                if (nums[i] != nums[i - 1]) {
                    nums[rsl++] = nums[i];
                }
            }
            return rsl;
        }
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        int[] nums = {1, 2, 2, 2, 3, 3, 4, 4, 4};
        System.out.println(s.removeDuplicates(nums));
        System.out.println(Arrays.toString(nums));
    }
}
